package collection;

import java.util.Collection;
import java.util.HashSet;

public class CollectionDemo1 {
    public static void main(String[] args) {
        //        Collection c = new ArrayList();
        Collection c = new HashSet();//不可以放重复元素的，并且无需
        /*
            boolean add(E e)
            将给定元素添加到集合中。如果元素成功添加到集合中则返回true
         */
        boolean b = c.add("one");
        System.out.println(b);
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        System.out.println(c);
        b = c.add("one");//存放重复元素
        System.out.println(b);
        System.out.println(c);
        /*
            int size()
            返回集合元素个数
         */
        int size = c.size();
        System.out.println("size:" + size);
        /*
            empty:空的
            boolean isEmpty()
            判断当前集合是否为一个空集(不含有任何元素)
         */
        boolean isEmpty = c.isEmpty();
        System.out.println("isEmpty:" + isEmpty);
        /*
            void clear()
            清空集合
         */
        c.clear();
        System.out.println(c);
        System.out.println("size:" + c.size());
        System.out.println("isEmpty:" + c.isEmpty());
    }
}
